package ext.sim.forces;

import ext.sim.Body;
import java.util.ArrayList;
import math.vec3;
import static math.vec3.norm;

/** Magnetic field force F = q(V x B). Assumes q = 1. */
public class ForceUniformMag implements Force
{
    
    private ArrayList<Body> rBodies;
    
    private vec3 mDir;
    
    private double mFieldStrength;
    
    
    public ForceUniformMag(
            ArrayList<Body> aBodies, 
            vec3 aDir, 
            double aFieldStrength)
    {
        this.rBodies = aBodies;
        this.mDir = norm(aDir);
        this.mFieldStrength = aFieldStrength;
    }
    
    
    public void apply()
    {
        for (Body b : this.rBodies)
        {
            vec3 qVxB = vec3.cross(b.mV, this.mDir);
            qVxB.mul(this.mFieldStrength);
            
            b.mF.add(qVxB);
        }
    }
    
}
